//package com.hwua.tonyshop.config;
//			
//import java.io.IOException;
//
//import javax.sql.DataSource;
//
//import org.apache.commons.logging.Log;
//import org.apache.commons.logging.LogFactory;
//import org.apache.ibatis.session.SqlSessionFactory;
//import org.mybatis.spring.SqlSessionFactoryBean;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
//import org.springframework.boot.context.properties.ConfigurationProperties;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.context.annotation.Primary;
//import org.springframework.core.io.DefaultResourceLoader;
//import org.springframework.core.io.Resource;
//import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
//import org.springframework.jdbc.datasource.DataSourceTransactionManager;
//import org.springframework.transaction.PlatformTransactionManager;
//import org.springframework.transaction.annotation.EnableTransactionManagement;
//import org.springframework.transaction.annotation.TransactionManagementConfigurer;
//import com.alibaba.druid.pool.DruidDataSource;
//
//@Configuration
//@EnableTransactionManagement
//public class MybatisConfiguration implements TransactionManagementConfigurer{
//	
//    private static Log logger = LogFactory.getLog(MybatisConfiguration.class);
//    
////  配置类型别名
//    @Value("${mybatis.typeAliasesPackage}")
//    private String typeAliasesPackage;
//    
////  配置mapper的扫描，找到所有的mapper.xml映射文件
//    @Value("${mybatis.mapperLocations}")
//    private String mapperLocations;
//    
////  加载全局的配置文件
//    @Value("${mybatis.configLocation}")
//    private String configLocation;
//    
//    @Autowired
//    private DataSource dataSource;
//    // DataSource配置
//	@Bean
//	@Primary
//    @ConfigurationProperties(prefix = "spring.datasource")
//    public DataSource primaryDataSource() {
//        return DataSourceBuilder.create().build();
//    }
//    
//    // 提供SqlSeesion
//    @Bean(name = "sqlSessionFactory")
//    public SqlSessionFactory sqlSessionFactoryBean() throws IOException {
//            SqlSessionFactoryBean sessionFactoryBean = new SqlSessionFactoryBean();
//            sessionFactoryBean.setDataSource(dataSource);
//            // 读取配置 
//            sessionFactoryBean.setTypeAliasesPackage(typeAliasesPackage);
//            // mapperLocations
//            Resource[] resources = new PathMatchingResourcePatternResolver()
//                    .getResources(mapperLocations);
//            sessionFactoryBean.setMapperLocations(resources);
////      //
//            sessionFactoryBean.setConfigLocation(
//                    new DefaultResourceLoader().getResource(configLocation));
//            //添加插件  （改为使用配置文件加载了）
////          sqlSessionFactoryBean.setPlugins(new Interceptor[]{pageHelper()});
//                    
//            try {
//				return sessionFactoryBean.getObject();
//			} catch (Exception e) {
//				// TODO Auto-generated catch block
//				e.printStackTrace();
//			}
//			return null;
//   }
//  
//    
////  @Bean
////    public SqlSessionTemplate sqlSessionTemplate(SqlSessionFactory sqlSessionFactory) {
////        return new SqlSessionTemplate(sqlSessionFactory);
////    }
//    
////  @Bean
////  public PlatformTransactionManager transactionManager(){
////      return new DataSourceTransactionManager(dataSource);
////  }
//    
//    
//    @Bean
//    public PlatformTransactionManager annotationDrivenTransactionManager() {
//        return new DataSourceTransactionManager(dataSource);
//    }
//    
//    
//}